package org.dev.vlp.controller;

import org.dev.vlp.bean.JsonResponse;
import org.dev.vlp.constants.Roles;
import org.dev.vlp.dto.CircleData;
import org.dev.vlp.dto.ColumnData;
import org.dev.vlp.dto.UserLoginParam;
import org.dev.vlp.entity.Book;
import org.dev.vlp.entity.Statistics;
import org.dev.vlp.interceptor.RequiredPermission;
import org.dev.vlp.service.DailyRecordService;
import org.dev.vlp.service.StatisticsService;
import org.dev.vlp.vo.DailyVo;
import org.dev.vlp.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description
 * Param
 * return
 * Author:86184
 * Date: 2023/1/15
 */
@RestController
@RequiredPermission({Roles.ROLE_USER})
public class StatisticsController extends BaseController{

    @Autowired
    private StatisticsService statisticsService;

    @Autowired
    private DailyRecordService dailyRecordService;

    @PostMapping("/setLan/{lanId}")
    public JsonResponse<Object> setLan(@PathVariable("lanId") int lanId) {
        statisticsService.setLan((int) getUid(),lanId);
        return JsonResponse.success();
    }

    @GetMapping("/getLan")
    public JsonResponse<Object> getLan() {
        int lan = statisticsService.getLan((int) getUid());
        return JsonResponse.success(lan);
    }

    @GetMapping("/getBook")
    public JsonResponse<Statistics> getMyBook() {
        Statistics book = statisticsService.getBook((int) getUid());
        return JsonResponse.success(book);
    }

    @GetMapping("/seven")
    public JsonResponse<Object> getLatestData() {
        ColumnData latestSevenDaysWordData = dailyRecordService.findLatestSevenDaysWordData((int) getUid());
        return JsonResponse.success(latestSevenDaysWordData);
    }

    @GetMapping("/review")
    public JsonResponse<Object> getReviewData() {
        List<CircleData> mmryPercentage = dailyRecordService.findMmryPercentage((int) getUid());
        return JsonResponse.success(mmryPercentage);
    }

    @GetMapping("/daily")
    public JsonResponse<DailyVo> getDailyData(@RequestParam int lan) throws ParseException {
        DailyVo dailyData = statisticsService.getDailyData(lan, (int) getUid());
        return JsonResponse.success(dailyData);
    }
}
